﻿using BaseUI;
using BLL;
using System;
using System.Data;

namespace Thksoft.MainAspx
{
    public partial class PipelineUnmatch : BasePage
    {
        private YX_BANK_LISTBLL bankBll = new YX_BANK_LISTBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            string InerHtmls = " <div ><ul>";
            //查询待办信息
            DataTable temp = bankBll.ProGetUnmatch(lognUser.USER_COMPANY.ToString(), " sysdate-1 >= D_TRANDATE ", " D_TRANDATE desc");

            if (temp != null)
            {
                Label1.Text = temp.Rows.Count.ToString();
            }

            if (temp.Rows.Count == 0)
            {
                //MainFrame.isOpenPipeline = true;
                MessageBox.ResponseScript(Page, "FORM_CLOSE();");
            }

            #region 未匹配流水

            if (temp != null && temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    string str = "【" + temp.Rows[i]["C_PROWEEKNUM"].ToString() + "】'" + temp.Rows[i]["C_CADBANK_NM"].ToString() + "' " + temp.Rows[i]["D_TRANDATE"].ToString();

                    str = SubStr(str);
                    InerHtmls += "<li><span>" + GetDate(temp.Rows[i]["D_TRANDATE"].ToString()).ToString() + "</span><a href='#' onclick=\"FORM_EDIT('" + temp.Rows[i]["N_DETAIL_LISTID"] + "');\">" + str;

                    DateTime time = DateTime.Parse(temp.Rows[i]["D_TRANDATE"].ToString()).AddDays(10);//10天以内的有图标
                    DateTime now = DateTime.Now;
                    if (time >= now)
                    {
                        InerHtmls += "<img src='/Images/main_right/new.gif'/> ";
                    }
                    InerHtmls += "</a></li>";
                }
            }

            #endregion 未匹配流水

            InerHtmls += "</ul></div> ";
            div1.InnerHtml = InerHtmls;
        }

        private string GetDate(string date)
        {
            string t = "";
            try
            {
                DateTime time = Convert.ToDateTime(date.ToString());

                decimal mouth = decimal.Parse(time.Month.ToString());
                decimal day = decimal.Parse(time.Day.ToString());
                if (mouth < 10 && day >= 10)
                {
                    t = "[ 0" + mouth + "-" + day + " ]";
                }
                else if (day < 10 && mouth >= 10)
                {
                    t = "[ " + mouth + "-0" + day + " ]";
                }
                else if (day < 10 && mouth < 10)
                {
                    t = "[ 0" + mouth + "-0" + day + " ]";
                }
                else
                {
                    t = "[ " + mouth + "-" + day + " ]";
                }
            }
            catch
            {
                DateTime time = DateTime.Now;
                decimal mouth = decimal.Parse(time.Month.ToString());
                decimal day = decimal.Parse(time.Day.ToString());
                if (mouth < 10 && day >= 10)
                {
                    t = "[ 0" + mouth + "-" + day + " ]";
                }
                else if (day < 10 && mouth >= 10)
                {
                    t = "[ " + mouth + "-0" + day + " ]";
                }
                else if (day < 10 && mouth < 10)
                {
                    t = "[ 0" + mouth + "-0" + day + " ]";
                }
                else
                {
                    t = "[ " + mouth + "-" + day + " ]";
                }
            }
            return t;
        }

        private string SubStr(string str)
        {
            if (str.Length > 50)
            {
                str = str.Substring(0, 50) + "...";
            }
            return str;
        }

        protected void Button_Bind_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}